#!/usr/bin/perl

########################################################
#@author Geemoney
#PERL: Pathologically Eclectic Rubbish Lister
########################################################

use warnings;
use strict;
use LWP::Simple;


##########################################################
#		  	  		found/actual
#alchemy:	  		297/297 --done http://www.wowhead.com/skill=171/alchemy
#blacksmithing:		588/588 --done
#enchanting:		351/351 --done
#engineering:		224/324 --done
#inscription:		471/471 --done
#jewelcrafting:   	601/601 --done
#leatherworking:	616/616 --done
#tailoring:			481/481 --done
#
###########################################################

my $c =0;
my $n;
my @colors;
my $key;
my $value;

my %proffesions = ();
my %newSpell = ();

my %url =(
	"alchemy", 'http://www.wowhead.com/skill=171/alchemy',
	"blacksmithing",'http://www.wowhead.com/skill=164/blacksmithing',
	"enchanting", 'http://www.wowhead.com/skill=333',
	"engineering",'http://www.wowhead.com/skill=202',
	"inscription",'http://www.wowhead.com/skill=773',
	"jewelcrafting", 'http://www.wowhead.com/skill=755',
	"leatherworking", 'http://www.wowhead.com/skill=165',
	"tailoring",'http://www.wowhead.com/skill=197' 
);


while (($key, $value) = each(%url))
{
	my @color = {};
	my @creates = {};
	my @reagents = {};
	my $name;
	my $i; my $j;
	my $content = get $value;
	die "Couldn't get $key, $value" unless defined $content;
	
	print "$key={ \n"; #start of table

	while( $content =~ m/(?>\{"cat":(.*?)(,|,"chrclass":(.*?),)"colors":\[(.*?)\](,|,"creates":\[(.*?)\],)"id":(.*?),"learnedat":(.*?),"level":(.*?),"name":"(.*?)","nskillup":(.*?)(,|,"races":\[(.*?)\],|,"rank":(.*?),)"reagents":\[(\[(.*?)\],|\[(.*?)\])\](.*?)(,|,"regrace":\[(.*?)\],)"schools":(.*?),"skill":\[(.*?)\](\}|,"source":\[(.*?)\](\}|,"trainingcost":(.*?)\})))/g ) 	
 	{	

		$name=substr($10, 1) ;
		@colors = split(/,/, $4);
		@creates = split(/,/, $6) if $6;
		@reagents = split(/,/, $15) if $15;
 		print "\t'$7':{\n";
 		print "\t\t'cat' : $1,\n" if $1;
 		print "\t\t'color' : {'orange' : $colors[0], 'yellow' : $colors[1], 'green' : $colors[2], 'grey' : $colors[3] },\n" if $4;
 		print "\t\t'creates' : {'item' : $creates[0], 'number' : $creates[1]},\n" if $6;
 		print "\t\t'id' : $7,\n" if $7;
 		print "\t\t'learnedat' : $8,\n" if $8;
 		print "\t\t'lvl': $9,\n" if $9;
 		print "\t\t'name' : \"$name\",\n" if $10;
 		print "\t\t'nskillup' : $11,\n" if $11; 		
		print "\t\t'races' : \"$13\",\n" if $13;
 		print "\t\t'reagents' : {\n" if $15;
        my $count=0;
		for($i=0; $i<scalar(@reagents); $i+=2){
			$reagents[$i]=substr($reagents[$i], 1) ;
			$reagents[$i+1]=substr($reagents[$i+1], 0,-1) ;
			print "\t\t\t '$count' : {'id':$reagents[$i], 'number':$reagents[$i+1]}";
			print ",\n" if $i<scalar(@reagents)-2;
			print "\n" if $i==scalar(@reagents)-2;
            $count++;
		}
		print "\t\t},\n" if $15;
 		#print "\t\tregrace = $15,\n" if $15;
 		print "\t\t'schools' : $21,\n" if $21;	
 		print "\t\t'skill' : $22,\n" if $22;
 		#print "\t\t'source' : $24,\n" if $24;
 		print "\t\t'trainingcost' : $26\n" if $26;
 		print "\t},\n";
 		$c++;

 	}
	
		
	
	print "}\n"; #end of table
}



